import {defineStore} from "pinia";
import {ref} from "vue";

export const useUserStore = defineStore("user", () => {
        const user = ref({
            userId: null,
            username: "",
            email: "",
            token: "",
            isLogin: false
        })

        const login = (loginUser) => {
            user.value.userId = loginUser.userId
            user.value.username = loginUser.username
            user.value.email = loginUser.email
            user.value.token = loginUser.token
            user.value.isLogin = true
        }

        const logout = () => {
            user.value = {
                userId: null,
                username: "",
                email: "",
                token: "",
                isLogin: false
            }
        }

        return {
            login,
            logout,
            user
        }
    },
    {
        persist: true
    })